﻿#ifndef DADATAMANAGERTABLEMODEL_H
#define DADATAMANAGERTABLEMODEL_H
#include <QAbstractTableModel>
#include "DAGlobals.h"
#include "DADataManagerInterface.h"
namespace DA
{
/**
 * @brief 对DataManager显示的的model
 */
class DADataManagerTableModel : public QAbstractTableModel
{
    Q_OBJECT
public:
    DADataManagerTableModel(DADataManagerInterface* dm, QObject* p = nullptr);
    ~DADataManagerTableModel();
    QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
    int columnCount(const QModelIndex& parent = QModelIndex()) const override;
    int rowCount(const QModelIndex& parent = QModelIndex()) const override;
    QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
    Qt::ItemFlags flags(const QModelIndex& index) const override;

public:
    QVariant dataDisplay(const DAData& d, const QModelIndex& index) const;
    QVariant dataDecoration(const DAData& d, const QModelIndex& index) const;
    QVariant dataBackground(const DAData& d, const QModelIndex& index) const;
    QVariant dataToolTip(const DAData& d, const QModelIndex& index) const;

public:
    //刷新
    void refresh(int row, int col);
private slots:
    void onDataBeginAdd(const DAData& d, int dataIndex);
    void onDataBeginRemove(const DAData& d, int dataIndex);
    void onDataEndAdded(const DAData& d, int dataIndex);
    void onDataEndRemoved(const DAData& d, int dataIndex);

private:
    DADataManagerInterface* _dataManagerInterface;
};
}  // namespace DA
#endif  // DADATAMANAGERMODEL_H
